package com.git.hui.yinshua.biz.rest.app.goods;

import com.git.hui.yinshua.api.model.ResVo;
import com.git.hui.yinshua.biz.goods.service.GoodsService;
import com.git.hui.yinshua.biz.order.service.PtOrderService;
import com.git.hui.yinshua.biz.rest.models.goods.rsp.GoodsInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YiHui
 * @date 2024/6/18
 */
@RestController
@RequestMapping(path = "app/goods")
public class GoodsIndexController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private PtOrderService ptOrderService;

    /**
     * 商品详情
     *
     * @param goodsId
     * @return
     */
    @GetMapping(path = "detail")
    public ResVo<GoodsInfoDto> detail(@RequestParam(name = "goodsId") Integer goodsId) {
        GoodsInfoDto info = goodsService.queryGoodsDetail(goodsId);
        if (info.getPtEnable()) {
            info.setPtOrderDtoList(ptOrderService.queryPtOrderListByGoodsId(goodsId));
        }
        return ResVo.ok(info);
    }
}
